/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myfx.jfxpanel;

import brain.MyBrain;
import controller.MyController;
import java.awt.Dimension;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.util.Callback;
import myfx.component.TextFieldTreeCellImpl;

/**
 *
 * @author Administrator
 */
public class MyTreeContainer extends JFXPanel{
    private int width;
    private int height;
    private MyController controller;
    private MyBrain brain;
    private Color color;
    TreeView<String> tree = new TreeView<String> ();  
    
    public MyTreeContainer(int width,int height,Color color){
        this.width=width;
        this.height=height;

        this.color=color;
        this.setPreferredSize(new Dimension(width, height));
    }
    public void addController(MyController controller){
        this.controller=controller;        
    }
    public void addBrain(MyBrain brain){
        this.brain=brain;
    }
    public void createMyTreeContainer(){
        Group group=new Group();
        
        ImageView back=new ImageView(new Image(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("MYFX/JFXPANEL/TREE_BK.PNG")));
        back.setTranslateY(-3);
        group.getChildren().add(back);
        
        Label fxLabel=new Label(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("巷道树状展示"));
        fxLabel.setTextFill(Color.WHITE);
        fxLabel.setFont(new Font(24));
        fxLabel.setTranslateX(76);
        
        TreeItem<String> rootItem = new TreeItem<String> (java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("采场"));
        TreeItem<String> gongzuomianItem=new TreeItem<String>(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("12014工作面"));
        TreeItem<String> zuanchangItem=new TreeItem<String>(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("1#钻场"));
        TreeItem<String> zhujiangkongItem=new TreeItem<String>(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("1-1"));
        group.getChildren().add(fxLabel);
        rootItem.setExpanded(true);   
        tree.setRoot(rootItem);
        tree.setPrefSize(width, height);
        tree.setTranslateY(30);
        
        VBox vBox=new VBox(tree);       
        group.getChildren().add(vBox);
        tree.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {

            public TreeCell<String> call(TreeView<String> p) {
                return new TextFieldTreeCellImpl(controller,brain);
            }
        });
        tree.setOnMouseEntered(new EventHandler<MouseEvent>() {

            public void handle(MouseEvent t) {
                tree.requestFocus();
            }
        });
        
        
        tree.setEditable(true);
        tree.setOpacity(0.73);
        Scene scene = new Scene(group,width,height,color);
        this.setScene(scene);
    }
    
    public TreeView<String> getTree() {
        return tree;
    }

    public void setTree(TreeView<String> tree) {
        this.tree = tree;
    }
}
